package org.mygui.test;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;

import javax.swing.*;

public class userjtable {

	public static void main(String args[]) {
	    JFrame frame = new JFrame();
	    frame.setBounds(100, 100, 500, 375);
	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	    JTable table = new JTable();
	    final UserTableModel userTableModel = new UserTableModel();
	    userTableModel.setUsers(Arrays.asList(new User("1", "fuxueliang")));
	    table.setModel(userTableModel);

	    frame.getContentPane().setLayout(new BorderLayout());
	    frame.getContentPane().add("Center", table);

	    JButton button = new JButton("Change Model");
	    
	    button.addActionListener(new ActionListener() {
	    	@Override
	      public void actionPerformed(ActionEvent e) {
	    		System.out.println("click......");
	        String current = String.valueOf(System.currentTimeMillis());
	        // 注意:这里修改了UserTableModel的list, 这个list可以是你从数据库上查出来的
	        userTableModel.setUsers(Arrays.asList(new User("2", current)));
	      }
	    });
	    frame.getContentPane().add("South", button);
	    frame.setVisible(true);
	  }
}
